package com.yohann.designPattern.iterator.output;

import com.yohann.designPattern.iterator.college.College;
import com.yohann.designPattern.iterator.department.Department;

import java.util.Iterator;
import java.util.List;

/**
 * <p>
 * 输出实现
 * </p>
 *
 * @author Yohann
 * @since 2021/2/12 16:17
 */
public class OutputImpl {
    private List<College> colleges;

    public OutputImpl(List<College> colleges) {
        this.colleges = colleges;
    }

    public void printCollege() {
        Iterator<College> iterator = colleges.iterator();
        while (iterator.hasNext()) {
            College college = iterator.next();
            System.out.println("************************");
            System.out.println(college.getName());
            System.out.println("========================");
            printDepartment(college.createIterator());
            System.out.println("========================");
            System.out.println();
        }
    }

    public void printDepartment(Iterator iterator) {
        while (iterator.hasNext()) {
            Department next = (Department) iterator.next();
            System.out.println(next.getName());
        }
    }
}